package se.webbzon.boltzmann.editor.component.portal;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JLabel;
import javax.swing.JTextField;

import se.webbzon.boltzmann.editor.component.AbstractComponent;
import se.webbzon.boltzmann.game.object.portal.AbstractPortal;

public class PortalPanel extends AbstractComponent {
	
	// Auto generated serial version UID
	private static final long serialVersionUID = -914397174081263016L;
	
	// The input fields for this property frame
	private final JTextField worldAreaInput, idInput;
	
	/*============================================================
	Constructors
	============================================================*/
	
	public PortalPanel(AbstractPortal instance) {
		super("Portal");
		
		setLayout(new BoxLayout(this,BoxLayout.Y_AXIS));
		setBorder(BorderFactory.createTitledBorder("Portal link data:"));
		
		// The world area name
		add(new JLabel("World Area Name (resource name):"));
		worldAreaInput = new JTextField(instance.getWorldAreaName());
		add(worldAreaInput);
		
		// The portal id
		add(new JLabel("Portal id (-128 to 127):"));
		idInput = new JTextField("" + instance.getPortalId());
		add(idInput);
	}
	
	/*============================================================
	Public Methods
	============================================================*/
	
	/** Returns the world area name provided in this portal portal. **/
	public String getWorldAreaName() {
		return worldAreaInput.getText();
	}
	
	/** Returns the id of the portal provided in this portal portal. **/
	public byte getPortalId() throws NumberFormatException {
		return Byte.parseByte(idInput.getText());
	}

}
